package entity;

import java.util.Date;

import org.apache.commons.lang.builder.HashCodeBuilder;

import util.DateUtil;

/**
 * Section entity.
 * 
 * @author huiwensong.2012, huangjm.2012, mohameds.2012, sheryl.tay.2012,
 *         jaslin.wee.2012
 * 
 */
public class Section {
	private Course course;
	private String sectionCode;
	private int dayOfWeek;
	private Date startTime;
	private Date endTime;
	private String instructor;
	private String venue;
	private int size;

	public Section(Course course, String sectionCode, int dayOfWeek,
			Date startTime, Date endTime, String instructor, String venue,
			int size) {
		this.course = course;
		this.sectionCode = sectionCode;
		this.size = size;
		this.dayOfWeek = dayOfWeek;
		this.startTime = startTime;
		this.endTime = endTime;
		this.instructor = instructor;
		this.venue = venue;
	}

	public Course getCourse() {
		return course;
	}

	public String getSectionCode() {
		return sectionCode;
	}

	public int getSize() {
		return size;
	}

	public int getDayOfWeek() {
		return dayOfWeek;
	}

	public String getStartTime(String pattern) {
		return DateUtil.formatDate(startTime, pattern);
	}

	public String getEndTime(String pattern) {
		return DateUtil.formatDate(endTime, pattern);
	}

	public Date getStartTime() {
		return startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public String getInstructor() {
		return instructor;
	}

	public String getVenue() {
		return venue;
	}

	@Override
	public String toString() {
		return "Section [courseCode=" + course.getCourseCode()
				+ ", sectionCode=" + sectionCode + ", dayOfWeek=" + dayOfWeek
				+ ", startTime=" + startTime + ", endTime=" + endTime
				+ ", instructor=" + instructor + ", venue=" + venue + ", size="
				+ size + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Section) {
			Section anotherObj = (Section) obj;
			return course.equals(anotherObj.getCourse())
					&& sectionCode.equals(anotherObj.getSectionCode());
		}
		return false;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 31).append(course.getCourseCode())
				.append(sectionCode).toHashCode();
	}

}
